﻿using System;
using System.Windows.Forms;
using Medicalsystem.MCP.FormDesigner.Property;

namespace Medicalsystem.MCP.FormDesigner.MyControls
{
    /// <summary>
    /// 控件 MultiTextBox 属性的XML转换
    /// </summary>
    public class MultiTextBoxPropertyXML : CtrlUIPropertyXML
    {
        /// <summary>
        /// 控件 MultiTextBox 属性的XML转换
        /// </summary>
        /// <param name="panelCtl"></param>
        public MultiTextBoxPropertyXML(MultiTextBox multiTxt)
            : base(multiTxt)
        {
            _multiTxt = multiTxt;
        }

        private MultiTextBox _multiTxt = null;

        public override string ToXML()
        {
            return "<MaxLength>" + _multiTxt.MaxLength.ToString() + "</MaxLength>" +
                       "<ReadOnly>" + (_multiTxt.ReadOnlyZ ? "1" : "0") + "</ReadOnly>" +
                       "<TextAlign>" + ((int)_multiTxt.TextAlign).ToString() + "</TextAlign>" +
                       "<ScrollBars>" + ((int)_multiTxt.ScrollBars).ToString() + "</ScrollBars>" +
                       "<Base>" + base.ToXML() + "</Base>";
        }

        public override void FromXML(System.Xml.XmlNodeList xns)
        {
            if (xns != null && xns.Count > 0)
            {
                foreach (System.Xml.XmlNode XN in xns)
                {
                    switch (XN.Name.ToLower())
                    {
                        case "maxlength":
                            _multiTxt.MaxLength = Convert.ToInt32(XN.InnerText);
                            break;

                        case "readonly":
                            _multiTxt.ReadOnlyZ = base.StringToBool(XN.InnerText);
                            break;

                        case "textalign":
                            _multiTxt.TextAlign = (HorizontalAlignment)Convert.ToInt32(XN.InnerText);
                            break;

                        case "scrollbars":
                            _multiTxt.ScrollBars = (ScrollBars)Convert.ToInt32(XN.InnerText);
                            break;

                        case "base":
                            base.FromXML(XN.ChildNodes);
                            break;

                        default:
                            break;
                    }
                }
            }
        }
    }
}